/**
 * 级联选择适配
 * @author xiufu.wang
 */
export default function applyAdapt(dataSource) {
    dataSource.cascaderAsyncload = function (node, cb) {
        const opt = dataSource.mergeOption
        const cascaderParams = typeof opt.cascaderParams === 'function' ? (opt.cascaderParams(node) || {}) : {}
        const queryFiled = opt.singleQueryField || 'query'
        const res = dataSource.shortLoadDatas({ [queryFiled]: (!node ? '' : node.value), ...cascaderParams }, true)
        if (res.then) {
            res.then((data) => {
                cb(dataSource.handleFormatDatas(data, dataSource.mergeOption) || [])
            })
        } else {
            cb(dataSource.handleFormatDatas(res, dataSource.mergeOption) || [])
        }
    }
}